df <- data.frame(x = 1:10, grp1 = rnorm(10, 5, 1), grp2 = rnorm(10, 10, 3))
pie <- data.frame(grp = c("grp1", "grp2"), value = c(6, 4), stringsAsFactors = FALSE)
df %>%
e_charts(x) %>%
e_line(grp1) %>%
e_line(grp2) %>%
e_data(pie, grp) %>%
e_pie(value, rm.x = FALSE, rm.y = FALSE, center = c("80%", "20%"), radius = c(0, 70)) %>%
e_title("Pie and Lines", "Linked legend") %>%
e_tooltip(trigger = "item") %>%
e_theme("shine")library(dplyr)
# download
flights <- jsonlite::fromJSON("https://ecomfe.github.io/echarts-examples/public/data-gl/asset/data/flights.json")
# airports
airports <- as.data.frame(flights$airports)
names(airports) <- flights$airportsFields
airports <- airports %>%
select(name, longitude, latitude) %>%
tibble::rownames_to_column("ID") %>%
mutate(ID = as.integer(paste0(ID)))
# routes
routes <- as.data.frame(flights$routes)
names(routes) <- c("ID", "from", "to")
# airlines
airlines <- as.data.frame(flights$airlines) %>%
tibble::rownames_to_column("ID") %>%
mutate(ID = as.integer(paste(ID))) %>%
select(ID, airline = V1, country = V2)
# bind
data <- routes %>%
inner_join(airports, by = c("from" = "ID")) %>%
inner_join(airports, by = c("to" = "ID"), suffix = c(".start", ".end")) %>%
inner_join(airlines, by = "ID") %>%
select(airline, longitude.start, latitude.start, longitude.end, latitude.end)
# split
spl <- split(data, data$airline)
# initialise plot
plot <- e_charts() %>%
e_globe(
base.texture = e_globe_dark_texture(),
environment = e_stars_texture(),
displacementScale = 0.1,
displacementQuality = "high",
shading = "realistic",
realisticMaterial = list(
roughness = .2,
metalness = 0
),
postEffect = list(
enable = TRUE,
depthOfField = list(
enable = FALSE
)
),
temporalSuperSampling = list(
enable = TRUE
),
light = list(
ambient = list(
intensity = 1
),
main = list(
intensity = .1,
shadow = FALSE
)
),
viewControl = list(autoRotate = FALSE)
) %>%
e_legend(
selectedMode = "single",
left = "left",
textStyle = list(color = "#fff"),
orient = "vertical"
)
# loop over groups
for(i in 1:length(spl)){
plot <-plot %>%
e_data(spl[[i]]) %>%
e_lines_3d(
longitude.start, latitude.start, longitude.end, latitude.end,
coord.system = "globe",
name = unique(spl[[i]]$airline)[1],
effect = list(
show = TRUE,
trailWidth = 2,
trailLength = 0.15,
trailOpacity = 1,
trailColor = 'rgb(30, 30, 60)'
),
lineStyle = list(opacity = 0.1, widh = 0.5, color = 'rgb(50, 50, 150)'))
}
plot # plotDownload the image
library(png)
download.file("http://www.gradhacker.org/wp-content/uploads/Rlogo.png", destfile = "Rlogo.png", mode = "wb")
png <- readPNG("Rlogo.png", native = FALSE)# extract colors
colors <- c(png[,,1], png[,,2], png[,,3])
# build as matrix of hex colors
matrix <- matrix(colors, nrow = dim(png)[1], ncol = dim(png)[2])
# reshape to x, y, color data.frame
df <- as.data.frame(as.table(matrix))
names(df) <- c("x", "y", "z")
df %>%
e_charts(x) %>%
e_bar_3d(y, z) %>%
e_grid_3d(show = FALSE) %>%
e_visual_map(
z,
show = FALSE,
calculable = FALSE
) %>%
e_theme("westeros")